package meijuli.com.join51.business.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ListView;

/**
 * Created by wenqin on 2017/3/21.
 */

public class VerticalListView extends ListView {

    private int mLastMotionY = 0;
    private int mLastMotionX = 0;
    private int xDistance, yDistance;
    private int mPosition;

    public VerticalListView(Context context) {
        super(context);
    }

    public VerticalListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public VerticalListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        boolean resume = false;
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                xDistance = yDistance = 0;
                mLastMotionX = (int) ev.getX();
                mLastMotionY = (int) ev.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                final int CurX = (int) ev.getX();
                final int CurY = (int) ev.getY();
                xDistance += Math.abs(CurX - mLastMotionX);
                yDistance += Math.abs(CurY - mLastMotionY);
                mLastMotionX = CurX;
                mLastMotionY = CurY;
                if (xDistance > yDistance) {
                    resume = super.onInterceptTouchEvent(ev);
                } else {
                    resume = false;
                }
                break;
            case MotionEvent.ACTION_UP:
                resume = false;
                break;
            default:
                break;
        }
        return resume;
    }
}
